package design.pattern.Lu11DecoratorPattern;

/**
 * @program JavaBase
 * @description: 装饰器模式
 * @author: zhanglu
 * @create: 2020-04-08 09:46:00
 */
public class DecoratorPattern {

    public static void main(String[] args) {

        SchoolReport sr = new FouthGradeSchoolReport();

        //一次装饰
        sr = new ReportDecorator(sr);

        //二次装饰
        sr = new SignDecorator(sr);

        sr.report();
        sr.sign("zhangsan");

    }

}

abstract class SchoolReport{

    public abstract void report();

    public abstract void sign(String name);

}

class FouthGradeSchoolReport extends SchoolReport{

    @Override
    public void report() {
        System.out.println("这是一份成绩单");
    }

    @Override
    public void sign(String name) {
        System.out.println("签名：" + name);
    }
}

abstract class Decorator extends SchoolReport{

    private SchoolReport sr;

    public Decorator(SchoolReport sr){
        this.sr = sr;
    }

    @Override
    public void report() {
        this.sr.report();
    }

    @Override
    public void sign(String name) {
        this.sr.sign(name);
    }
}

class ReportDecorator extends Decorator{

    public ReportDecorator(SchoolReport sr) {
        super(sr);
    }

    @Override
    public void report() {
        System.out.println("解说成绩单");
        super.report();
    }

}

class SignDecorator extends Decorator{

    public SignDecorator(SchoolReport sr) {
        super(sr);
    }

    @Override
    public void report() {
        System.out.println("不解说成绩单");
        super.report();
    }

    @Override
    public void sign(String name) {
        System.out.println("解说签名");
        super.sign(name);
    }
}



